﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Volo.Abp.AspNetCore.Mvc;

namespace Artizan.Iot.Hub.Mqtt.AspNetCore.Controllers;

[Area("MqttServerHost")]
[Route(IotHubMqttAspNetCoreConsts.MqttServerHostHeartbeatUrl)]
public class MqttServerHostHeartbeatController  : AbpController
{
    private readonly ILogger<MqttServerHostHeartbeatController > _logger;

    public MqttServerHostHeartbeatController (ILogger<MqttServerHostHeartbeatController > logger)
    {
        _logger = logger;
    }

    /// <summary>
    /// MQTT server 宿主心跳接口，用于如下场景：
    /// 当 MQTT server 宿主部署在 IIS 时， 宿主应用程序闲置一定时间后进程会被回收，导致 MQTT server(broker)无法连接, 
    /// 可以周期性调用该接口，保证部署在IIS的宿主应用程序一直处于激活状态, 保证  MQTT server(broker) 可连接。
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public IActionResult GetHeartbeat()
    {
        var message = $"MQTT server host heartbeat received at: {DateTimeOffset.Now}";
        _logger.LogDebug(message);

        return Ok(message);
    }
}
